<?php
	namespace Home\Controller;
	use Think\Controller;
	
	class TtoController extends Controller
	{
		public function index()
		{
			//获取sikaoID
			$newid=$_GET['newid'];
			//判断是否获取ID
			if($newid!=null){
				
			
				//查tto的id与用户表的拼接值
				//查id
				$ttoid=M("tbid")->field('ttoid')->where("id=1")->find();
				$ttoid=$ttoid['ttoid'];
				//查用户表
				$result=$_SESSION["usersk"];
				$userName=$_SESSION["usersk"]["userName"];
				$password=$_SESSION["usersk"]["password"];
				$newid1=$userName.$password.$ttoid;
				
				//判断是否相同
				if($newid==$newid1)
				{
					$_SESSION["usertto"]=$result;
					$this->success("登录成功！请在TTO网刷新页面即可",__APP__."/index/index");
				}else
				{
					$this->success("请先登录思考网！",__APP__."/Login/index");
				}
				
				
			}else{
				$session=$_SESSION["usertto"]["userName"];
				$a=rand(1,100);
				$arr=array('ttoid'=>$a);
				//将随机数存入数据库
				$save = M('tbid')->where("id=1")->save($arr);
				$this->assign('session',$session);
				$this->assign('a',$a);
				$this->display();
			}
			
		}
		//退出登录
		public function outLogin()
		{
			unset($_SESSION['usertto']);
			$this->success("退出成功",__APP__."/tto/index");
		}
	}
?>